package com.li.controller;


import com.li.pojo.dto.DictTypeDTO;
import com.li.pojo.dto.DictTypePageDto;
import com.li.pojo.po.DictType;
import com.li.pojo.po.PageResult;
import com.li.pojo.po.Result;
import com.li.service.DictTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

//字典类型管理
@Slf4j
@RestController
@RequestMapping("/system/dict/type")
public class DictTypeController {
    @Autowired
    private DictTypeService dictTypeService;

    //添加
    @PostMapping
    public Result add(@RequestBody DictTypeDTO dictTypeVo){
        dictTypeService.add(dictTypeVo);
        return new Result(200,"添加字典类型成功",null);
    }

    //分页查询
    @GetMapping("/list")
    public PageResult findByPage(DictTypePageDto pageDto){
        log.info("{}",pageDto);
        PageResult page=dictTypeService.findByPage(pageDto);
        return page;
    }

    //根据id查询字典类型
    @GetMapping("/{dictId}")
    public Result findById(@PathVariable Integer dictId){
        DictType dictType=dictTypeService.findById(dictId);
        return new Result(200,"查询成功",dictType);
    }

    //根据ids删除字典类型
    @DeleteMapping("/{dictIds}")
    public Result deleteByIds(@PathVariable List<Integer> dictIds){
        log.info("删除ids:{}",dictIds);
        dictTypeService.deleteByIds(dictIds);
        return new Result(200,"删除成功",null);
    }

    //修改字典类型
    @PutMapping
    public Result updateDictType(@RequestBody DictTypeDTO dictTypeDTO){
        dictTypeService.updateDictType(dictTypeDTO);
        return new Result(200,"修改成功",null);
    }

    //导出
    @GetMapping("/export")
    public void export(DictTypePageDto pageDto, HttpServletResponse response){
        log.info("{}",pageDto);
        dictTypeService.export(pageDto,response);
    }

    //清理缓存
    @DeleteMapping("/clearCache")
    public Result clearCache(){
        return new Result(200,"清理成功",null);
    }
}
